package com.apes.fn.controlWaitDisposal;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Name;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.jpa.tuple.date.DateTime;
import com.apes.framework.plugin.soe.annotations.State;
import com.apes.framework.plugin.soe.annotations.States;
import com.apes.framework.util.ApesConst;
import com.apes.framework.util.DateUtil;
import com.apes.scm.masterdata.frame.model.Dept;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenerationTime;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;

/**
 * @program: apes-server
 * @description 未提交方案表
 * @author: czs
 * @create: 2021-05-21 13:54
 **/
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = WaitSubmission.CONST_TABLE_NAME)
public class WaitSubmission extends BaseModel {
    public static final String CONST_TABLE_NAME = "fn_service_wait_submission";

    @Id
    @Column(name = "id", nullable = false, length = 24)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "未提交方案表", padding = 12)
    private String id;

    @Column(name = "service_plan_source", length = 32)
    @Comment("来源方案号")
    private String servicePlanSource;   //用于做操作，方便从另外一个方案找到初始方案明细

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "belong_dept_id", referencedColumnName = "id", nullable = false)
    @Comment("所属门店")
    private Dept belongDept;  //区分，该单据属于哪个门店，权限用

    @States(name = "方案状态", values = {
            @State(id = "create", name = "新增"),
            @State(id = "toTechAudit", name = "转技术审核"),
            @State(id = "techAudit", name = "技术审核完成"),
            @State(id = "backTechAudit", name = "技术审核退回"),
            @State(id = "toPriceAudit", name = "转价格审核"),
            @State(id = "priceAudit", name = "价格审核"),
            @State(id = "backPriceAudit", name = "价格审核退回"),
            @State(id = "toInquiry", name = "转询价"),
            @State(id = "inquiryFinish", name = "询价完成"),
            @State(id = "backInquiry", name = "询价退回"),
            @State(id = "submission", name = "提交"),
            @State(id = "goBack", name = "退回"),
            @State(id = "confirm", name = "确认"),
            @State(id = "qualityTest", name = "质检"),
            @State(id = "termination", name = "终止"),
//            @State(id = "toReceivables", name = "转收款"),  质检完成直接转收款
            @State(id = "receivables", name = "收款完成")
    })
    @Column(name = "state", length = 32, nullable = false)
    private String state = "create";

    @Column(name = "sales_amount", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("方案结算金额")
    private double salesAmount = 0;

    @Column(name = "serve_type_name",length = 255)
    @Comment("服务类型名称")
    private String serveTypeName;

    @Name
    @Column(name = "car_license", length = 64)
    @Comment("车牌号码")
    private String carLicense;

    @Column(name = "valid", nullable = false, columnDefinition = "number(1,0) default 1")
    @Comment("是否提交标记")
    private boolean valid = true; //1是未提交

    @Column(name = "plan_create_date", updatable = false)
    @Comment("方案创建时间")
    private Date planCreateDate;

}
